package com.example.smartplay.controller;


import com.example.smartplay.entity.Comments;
import com.example.smartplay.entity.Result;
import com.example.smartplay.service.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 
 * @since 2024-07-11
 */
@RestController
@RequestMapping("/comments")
public class CommentsController {
    @Autowired
    private CommentsService commentsService;

        //分页查询留言
    @RequestMapping("/getcomments/{pageNum}/{pageSize}")
    public Result getcomments(
            @PathVariable("pageNum") Integer pageNum,
            @PathVariable("pageSize") Integer pageSize
    ) {
        return commentsService.getcomments(pageNum, pageSize);
    }

   //新增评论
    @RequestMapping("/save")
    public Result saveOrUpdate(@RequestBody Comments comments) {
        commentsService.save(comments);
        return Result.success();
    }

    //删除和批量删除评论
    @RequestMapping("/delete/{ids}")
    public Result delete(@PathVariable List<Integer> ids) {
        commentsService.removeByIds(ids);
        return Result.success();
    }

}
